package tcu.iot.gasmanage.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tcu.iot.gasmanage.common.Result;
import tcu.iot.gasmanage.common.utils.DateUtils;
import tcu.iot.gasmanage.common.utils.EquipmentInfoResultUtils;
import tcu.iot.gasmanage.entity.equipment.EquipmentInfoResult;
import tcu.iot.gasmanage.entity.linechart.LineChartQuery;
import tcu.iot.gasmanage.mapper.TDengineMapper;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class LineChartService {
    //获取图表数据
    public Result getData(LineChartQuery lineChartQuery) {
        List<String> list = new ArrayList<>();
        List<EquipmentInfoResult> list1;

        if (lineChartQuery.getDate() != null) {
            for (int i = 0; i < 2; i++) {
                list.add(DateUtils.dealDateFormat(lineChartQuery.getDate().get(i)));
            }

            list1 = TDengineMapper.DateLineChartData(lineChartQuery.getEquipmentNumber(), list.get(0), list.get(1));
        } else {
            list1 = TDengineMapper.AllLineChartData(lineChartQuery.getEquipmentNumber());
        }

        return EquipmentInfoResultUtils.EquipmentInfoDataResult(list1);
    }
}
